package com.lu.manage.modular.system.controller;

import com.lu.manage.core.base.controller.BaseController;
import com.lu.manage.core.common.exception.SysLogExcepetion;
import com.lu.manage.core.tips.SuccessTip;
import com.lu.manage.modular.system.model.ExceptionLog;
import com.lu.manage.modular.system.service.ExceptionLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @Project LuBoot
 * @Author: zhanglu
 * @Date: 2019-11-16 13:20:46
 * @Description: 博客异常日志 控制器
 */
@Controller
@RequestMapping("/system/exceptionLog")
public class ExceptionLogController extends BaseController {

    private static final String PREFIX = "/modular/system/exceptionLog";

    @Autowired
    private ExceptionLogService exceptionLogService;


/*******************************跳转页面相关*******************************/

    /**
    * 首页
    * @return
    */
    @RequestMapping("")
    public String index(){
        return PREFIX + "/index.html";
    }

    /**
    * 新增
    * @return
    */
    @RequestMapping("/toAdd")
    public String toAdd() {
        return PREFIX + "/add.html";
    }

    /**
    * 修改
    * @return
    */
    @RequestMapping("/toUpdate")
    public String toUpdate(String id, Model model) throws SysLogExcepetion {
        ExceptionLog obj = exceptionLogService.getById(id);
        model.addAttribute("obj", obj);
        return PREFIX + "/update.html";
    }

/*******************************操作按钮相关*******************************/

    /**
     * 添加
     */
    @RequestMapping("/add")
    @ResponseBody
    @RequiresPermissions(value = "/system/exceptionLog/add")
    public Object add(ExceptionLog exceptionLog) throws SysLogExcepetion {
        exceptionLogService.addObj(exceptionLog);
        return new SuccessTip();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ResponseBody
    @RequiresPermissions(value = "/system/exceptionLog/update")
    public Object update(ExceptionLog exceptionLog) throws SysLogExcepetion {
        exceptionLogService.updateObj(exceptionLog);
        return new SuccessTip();
    }

    /**
     * 删除&批量
     */
    @RequestMapping("/delete")
    @ResponseBody
    @RequiresPermissions(value = "/system/exceptionLog/delete")
    public Object delete(String data) throws SysLogExcepetion {
        exceptionLogService.deleteObj(data);
        return new SuccessTip();
    }


/*******************************查询数据相关*******************************/

    /**
    * 分页查询
    */
    @RequestMapping("/listPage")
    @ResponseBody
    public Object listPage(@RequestParam Map<String, Object> map) throws SysLogExcepetion {
        return exceptionLogService.listPage(map);
    }

}
